package org.payeco.risk.controller;

import java.util.List;

import org.payeco.risk.dao.PayecoRiskRuleRepository;
import org.payeco.risk.dao.PayecoRuleModeRepository;
import org.payeco.risk.dao.PayecoRuleModularRepository;
import org.payeco.risk.entity.PayecoRiskRule;
import org.payeco.risk.entity.PayecoRuleMode;
import org.payeco.risk.entity.PayecoRuleModular;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yps
 *
 */
@RestController
public class PayecoModeController {
    @Autowired
    PayecoRuleModeRepository modeRepository;

    @RequestMapping("/saveMode")
    public PayecoRuleMode save(String modeNo, String modeName) {
    	PayecoRuleMode mode = modeRepository.save(new PayecoRuleMode(modeNo, modeName));
        return mode;
    }
 
    @RequestMapping("/queryMode")
    public List<PayecoRuleMode> queryModes(String state) {
        List<PayecoRuleMode> modes = modeRepository.findByState(state);
        return modes;
    }

    @RequestMapping("/queryByModeNo")
    public PayecoRuleMode queryByModeNo(String modeNo) {
    	PayecoRuleMode mode = modeRepository.findByModeNo(modeNo);
        return mode;
    }

    @RequestMapping("/modes_sort")
    public List<PayecoRuleMode> sort() {
        List<PayecoRuleMode> modes = modeRepository.findAll(new Sort(Sort.Direction.ASC, "priority"));
        return modes;
    }
    @RequestMapping("/modes_page")
    public Page<PayecoRuleMode> page(int page,int size){
        Page<PayecoRuleMode> all = modeRepository.findAll(new PageRequest(page, size));
        return all;
    }
    @RequestMapping("/modes_all")
    public List<PayecoRuleMode> all(){
        return modeRepository.findAll();
    }
}
